/*
 * Created on 14.04.2011
 *
 * @author Benedikt
 *
 * createt first in Project Ch@t
 */

package listener;

import general.Tree;
import interfaces.Variablen;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import window.Fenster;
import window.SplitPanel;

public class MyMouseListener extends MouseAdapter implements Variablen {

	Tree tree;
	SplitPanel splitPanel;
	private static String neuerTab;
	private static Fenster fenster;
	private static boolean offen;
	public MyMouseListener(Tree tree, Fenster fenster, SplitPanel splitPanel) {

		this.tree = tree;
		MyMouseListener.setFenster(fenster);
		this.splitPanel = splitPanel;
		
		
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		
		if (tree.tree.getSelectionCount() != 0) {
			String command = tree.tree.getSelectionPath().toString();
			System.out.println(tree.tree.getSelectionPath().toString());
			if (e.getClickCount() == 2) {
				
				if ((command.equals("[Allgemein, Freund 1]"))) {
					System.out.println("Fenster offen");
					if(!isOffen()){
					new Fenster(title, tree, splitPanel).setVisible(true);
					offen = true;
					}
					setNeuerTab(command);
					getFenster().tab.addTab(getNeuerTab(), new SplitPanel(getFenster()));
				}
				if ((command.equals("[Allgemein, Freund 2]"))) {
					System.out.println("Fenster offen");
					if(!isOffen()){
						new Fenster(title, tree, splitPanel).setVisible(true);
						offen = true;
						}
						setNeuerTab(command);
						getFenster().tab.addTab(getNeuerTab(), new SplitPanel(getFenster()));
					
				}
				if ((command.equals("[Allgemein, Freund 3]"))) {
					System.out.println("Fenster offen");
					if(!isOffen()){
						new Fenster(title, tree, splitPanel).setVisible(true);
						offen = true;
						}
						setNeuerTab(command);
						getFenster().tab.addTab(getNeuerTab(), new SplitPanel(getFenster()));
				}
				if ((command.equals("[Allgemein, Freund 4]"))) {
					System.out.println("Fenster offen");
					if(!isOffen()){
						new Fenster(title, tree, splitPanel).setVisible(true);
						offen = true;
						}
						setNeuerTab(command);
						getFenster().tab.addTab(getNeuerTab(), new SplitPanel(getFenster()));
				}
			}
		}
	}

	public static void setNeuerTab(String neuerTab) {
		MyMouseListener.neuerTab = neuerTab;
	}

	public static String getNeuerTab() {
		return neuerTab;
	}

	public static void setFenster(Fenster fenster) {
		MyMouseListener.fenster = fenster;
	}

	public static Fenster getFenster() {
		return fenster;
	}

	public static void setOffen(boolean offen) {
		MyMouseListener.offen = offen;
	}

	public static boolean isOffen() {
		return offen;
	}
}
